package com.uinnova.product.eam.base.web.http;

import com.uinnova.product.eam.base.web.http.response.CustomHttpServletResponseWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.servlet.*;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 该拦截器为了复写response，为了切面日志读取结果 不在这直接做日志是为了可以通过切面看到请求路由到的方法
 * <p>
 * 通过{@link CustomHttpServletResponseWrapper} 拷贝一份
 * {@link ServletResponse}的body内容
 * 
 * @author zhaoyujie
 *
 */
// @WebFilter(urlPatterns = "/*")
@Component
// @Order(1)
@Slf4j
public class ResponseFilter implements Filter {

    {
        log.info("response请求拦截器注册成功");
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
            throws IOException, ServletException {
        chain.doFilter(request, new CustomHttpServletResponseWrapper((HttpServletResponse) response));
    }
}
